package com.zidian.teacher.api;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import com.zidian.teacher.common.Constant;

/**
 * Created by GongCheng on 2016/10/17 0017.
 */

public class TeacherApi {
    private static TeacherApi instance;
    private TeacherApiService service;

    public TeacherApi( ) {
        OkHttpClient client = new OkHttpClient.Builder()
                .readTimeout(30, TimeUnit.SECONDS)
                .build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constant.URL_GOAL)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();
        service = retrofit.create(TeacherApiService.class);
    }

    /**
     * 单例获取TeacherApi实例
     * @return
     */
    public static TeacherApi getInstance( ) {
        if (instance == null) {
            instance = new TeacherApi();
        }
        return instance;
    }

    /**
     * 用户登录接口
     * @param username 用户名
     * @param password 密码
     * @return
     */
    public Observable<LoginResult> login(String username,String password) {
        return service.login(username,password);
    }
}
